import DataCenter from "../GlobalData/DataCenter";

export default class game_over_panel extends Laya.Script {
    constructor() { super(); }

    private time_text:Laya.Text              //时间文本节点
    private rate_text:Laya.Text              //速度文本节点
    private right_text:Laya.Text             //正确率文本节点
    private again_btn:Laya.Sprite            //再来一次按钮节点
    private title_text:Laya.Text             //结束标题文本

    onEnable(): void 
    {
        //初始化变量
        this.initParams()
        //初始化事件
        this.initEvent()
    }
    /**初始化事件 */
    initEvent()
    {
        //绑定点击事件
        this.again_btn.on(Laya.Event.CLICK,this,this.onAgain)
    }
    onAgain()
    {
        
        DataCenter.player_distance=0
        //重新打开场景，重置游戏
        Laya.Scene.open("game_scene.scene")
    }
    /**初始化面板数据 */
    initPanel(time:string,rate:string,right:string,isWin:boolean)
    {
        //初始化时间文本
        this.time_text.text=time
        //初始化速度文本
        this.rate_text.text=rate
        //初始化正确率文本
        this.right_text.text=right
        if(!isWin)
        {
            this.title_text.text="你输了"
        }
    }

    /**
     * 初始化变量
     */
    initParams()
    {
        //获取时间文本节点
        this.time_text=this.owner.getChildByName("time_text") as Laya.Text
        //获取速度文本节点
        this.rate_text=this.owner.getChildByName("rate_text") as Laya.Text
        //获取正确率文本节点
        this.right_text=this.owner.getChildByName("right_text") as Laya.Text
        //获取再来一次按钮节点
        this.again_btn=this.owner.getChildByName("again_btn") as Laya.Sprite
        this.title_text=this.owner.getChildByName("title_img")
                            .getChildByName("title_text") as Laya.Text
    }

    onDisable(): void {
    }
}